package bTree.LeetCode;

public class 路径总和 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        int path=0;
        return dfs(root,targetSum,path);
    }

    private boolean dfs(TreeNode node, int targetSum, int path) {
        if(node==null){
            return false;
        }
        path+=node.val;
        if(node.left==null&&node.right=null){
            if(path==targetSum){
                return true;
            }
        }
       if (dfs(node.left,targetSum,path)==true){
           return true;
       }
        if(dfs(node.right,targetSum,path)==true){
            return true;
        }
        return false;
    }
}